package com.hgq.tenadmin.md.client.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hgq.tenadmin.md.client.dao.MdClientDao;
import com.hgq.tenadmin.md.client.param.ClientParam;
import com.hgq.tenadmin.md.client.service.MdClientService;
import com.hgq.tencommon.entity.md.client.MdClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;

@Service
public class MdClientServiceImpl implements MdClientService {
    @Resource
    private MdClientDao mdClientDao;

    @Override
    public List<MdClient> findAllClientNoPage() {
        List<MdClient> mdClients = mdClientDao.selectAllClientNoPage();
        return mdClients;
    }

    @Override
    public  List<MdClient> selectAllSalePeopleByClientName(String clientName) {
        List<MdClient> mdClients = mdClientDao.selectAllSalePrincipalByClientName(clientName);
        return mdClients;
    }

    @Override
    public PageInfo<MdClient> selectAllClient(String clientName,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MdClient> mdClients = mdClientDao.selectAllClient(clientName);
        List<MdClient> mdClientList =  new ArrayList<>();
        for (MdClient mdClient : mdClients) {
            if (mdClient.getState()==1){
               mdClientList.add(mdClient);
            }
        }
        PageInfo<MdClient> mdClientPageInfo = new PageInfo<>(mdClientList);
        return mdClientPageInfo;
    }
    @Override
    public PageInfo<MdClient> selectSeaAllClient(String clientName, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MdClient> mdClients = mdClientDao.selectAllClient(clientName);
        List<MdClient> mdClientList =  new ArrayList<>();
        for (MdClient mdClient : mdClients) {
            if (mdClient.getState()==0){
                mdClientList.add(mdClient);
            }
        }
        PageInfo<MdClient> mdClientPageInfo = new PageInfo<>(mdClientList);
        return mdClientPageInfo;
    }

    @Override
    public void saveOneClient(ClientParam clientParam) {
        mdClientDao.insertOneClient(clientParam);
    }

    @Override
    public void updateOneClient(ClientParam clientParam) {
        mdClientDao.updateOneClient(clientParam);
    }

    @Override
    public void deleteOneClient(Integer cid) {
        mdClientDao.deleteOneClient(cid);
    }

    @Override
    public void updateClientToSea(Integer cid) {
        mdClientDao.updateClientToSea(cid);
    }
}
